package com.woniuxy.shop.web;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.commons.entity.ResponseResult;
import com.woniuxy.shop.entity.Shop;
import com.woniuxy.shop.mapper.ShopMapper;
import com.woniuxy.shop.service.ShopService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("shop")
public class ShopController {

    @Resource
    private ShopService shopService;


    //新增
    @PostMapping("add")
    public ResponseResult add(Shop shop) {
        shopService.save(shop);
        return new ResponseResult<>(200,"新增门店成功",null);
    }

    //修改
    @PostMapping("update")
    public ResponseResult update(Shop shop) {
        UpdateWrapper<Shop> wrapper = new UpdateWrapper<>();
        wrapper.eq("sid",shop.getSid());
        shopService.update(shop,wrapper);
        return new ResponseResult<>(200,"修改门店成功",null);
    }

    //分页
    @RequestMapping("page")
    public Page<Shop> findByPage(Page page) {
        return shopService.findByPage(page);
    }

    //根据店ID 查询详情
    @PostMapping("viewShop")
    public Shop viewShop(int sid) {

        return shopService.viewShop(sid);
    }

    //根据地址查询店
    @PostMapping("findByAddr")
    public Shop findByAddr(String addr) {

        return shopService.findByAddr(addr);
    }


    //根据店名查询店
    @PostMapping("findByName")
    public Shop findByName(String name) {

        return shopService.findByName(name);
    }
    

}
